/******************************************
	DefencePatrol.sqf
	Patrols friendly locations

	Converted - Xealot 2011-03-02 
*******************************************/
_veh = _this select 0;

_aiDefPoints = [side _veh] call fGetAllPoints;

_startPos = [_veh, _aiDefPoints] call fGetNearestArray;
_veh doMove getPos _startPos;

sleep 20;

waitUntil {unitReady _veh};

while {alive _veh} do {
	/* Update the areas to defend */
	_aiDefPoints = [side _veh] call fGetAllPoints;

	_nr = count _aiDefPoints;
	if (_nr == 0) then {
		/* There are no points to defend, wait 30 seconds and then check again */
		Sleep 30;
	} else {
		//_nr = _nr - 1;
		_i = Round(random _nr);
		_defObj = _aiDefPoints select _i;
		
		_veh doMove getPos _defObj;
		sleep 5;
		waitUntil {unitReady _veh};	
	};
};